﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;


namespace ZooSystem
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class Authorization : Window
    {
        Serialization database;
        UserData current_user;

        public Authorization()
        {
            database = Serialization.getDatabase();
            current_user = null;
            InitializeComponent();
        }

        private void LogIn_Btn_Click(object sender, RoutedEventArgs e)
        {

            string login = Login.Text;
            string password = Password.Password;
            foreach (UserData user in database.UsersList)
                if (user.valid_user(login, password))
                {
                    current_user = user;
                    break;
                }
            if (current_user == null)
            {
                MessageBoxResult result = MessageBox.Show(this, "Wrong user data",
                                "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {
                Window profile = null;
                if (current_user.users_type == type.user)
                    profile = new VisitorPanel();
                else if (current_user.users_type == type.admin)
                    profile = new AdminPanel(); 
                else if (current_user.users_type == type.employee)
                    profile = new WorkerMain();

                if (profile != null)
                {
                    this.Hide();
                    profile.ShowDialog();
                    current_user = null;
                    Login.Clear();
                    Password.Clear();
                    this.Show();
                }
            }


        }

        private void SignIn_Btn_Click(object sender, RoutedEventArgs e)
        {
            Registration registration = new Registration();
            registration.ShowDialog();
        }

    }
}
